<template>
    <div class="sign-up-info">
        <div class="search-content">
            <el-input class="search-content-input" v-model="searchContent.groupName" placeholder="请输入团购名称"></el-input>
            <div class="time-range-wrapper" >
                <span class="time-range-label">请选择添加时间：</span>
                <el-date-picker
                        v-model="searchContent.addTime"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                </el-date-picker>
            </div>
            <el-input class="search-content-input" v-model="searchContent.userName" placeholder="请输入姓名"></el-input>
            <el-input class="search-content-input" v-model="searchContent.userPhone" placeholder="请输入电话"></el-input>
            <!-- <el-input class="search-content-input" v-model="searchContent.signUpChannel" placeholder="请输入报名渠道"></el-input> -->
            <!-- <el-input style="width: 0;visibility: hidden;" class="search-content-input" v-model="searchContent.employeeName" placeholder="请输入员工姓名"></el-input> -->
            <el-select v-model="searchContent.signUpChannel" placeholder="请选择报名渠道">
                <el-option
                        v-for="item in channelList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
            <el-select v-model="searchContent.payStatus" placeholder="请选择支付状态">
                <el-option
                        v-for="item in payStatusList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button type="primary" @click="resetSearchData">重置</el-button>
        </div>
        <div class="search-list">
            <el-table :data="signUpInfoList" border :height="oHeight">
                <el-table-column
                        align="center"
                        prop="id"
                        label="ID"
                        min-width="60"></el-table-column>
                <el-table-column
                        align="center"
                        prop="userName"
                        label="姓名"
                        min-width="120"></el-table-column>
                <el-table-column
                        align="center"
                        prop="userPhone"
                        label="电话"
                        min-width="120"></el-table-column>
                <el-table-column
                        align="center"
                        label="订单编号"
                        prop="orderSerialNumber"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="groupName"
                        label="团购名称"
                        min-width="90">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="groupCategory"
                        label="团购类型"
                        min-width="90">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="报名时间"
                        min-width="120">
                    <template slot-scope="scope">
                        <span>{{scope.row.signUpTime | dateFormatter('YYYY-MM-DD ')}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="channel"
                        label="渠道"
                        min-width="90">
                        <template slot-scope="scope">
                            <!-- <span>{{scope.row.channel}}</span> -->
                            {{computedCheckStatus(scope.row.channel)}}
                        </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="intentionMoney"
                        label="意向金"
                        min-width="90">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="是否支付"
                        min-width="90">
                    <template slot-scope="scope">
                        <span>{{(scope.row.payStatus == 20 ? '已支付' : '待支付')}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        label="操作"
                        min-width="120">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="refund(scope.row)">退款</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group" style="width: 0;visibility: hidden;">
                    <a class="btn-bottom" :href="exportLink">导出</a>
                </div>
                <div class="paginationOne">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="searchContent.currentPage"
                            :page-sizes="[10, 20, 50, 100]"
                            :page-size="searchContent.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {dateFormatter} from "../../../../common/js/util";
	import { resize } from "@/common/js/height.js";
	import Qs from 'qs'

	export default {
		data() {
			return {
               
				payStatusList: [
					{label: '未支付', value: 10},
					{label: '已支付', value: 20},
					{label: '已退款', value: 3}
                ],
               
                channelList: [
					
					{label: '微信', value: "2,4"},
                    
                    {label: '支付宝', value: 10},
                    {label: 'H5', value: 6},
					{label: '小程序', value: 8},
                    {label: 'APP', value: 9},
                    {label: '其他', value: 999}


                ],
                
				oHeight: 800,
				searchContent: {
					groupName: '',
					userName: '',
					userPhone: '',
					payStatus: '',
                    signUpChannel: '',
                    addTime: '',
			        employeeName: ''
				},
				signUpInfoList: [],
				total: 0
			}
		},
		computed: {
			exportLink() {
				const data = {};
				data.export = 'yes';
				data.bg_name = this.searchContent.groupName;
				data.sign_name = this.searchContent.userName;
				data.search_telephone = this.searchContent.userPhone;
				data.pay_status = this.searchContent.payStatus;
				data.bg_source = this.searchContent.signUpChannel;
				data.employee_name = this.searchContent.employeeName;
				let domain = document.domain;
				if (domain != 'admin.mycjj.com' && domain != 'admin.chejj.cn') {
					domain = 'admin.chejj.cn'
                }
				return location.protocol + '//' + domain.replace('admin', 'api') + '/brandgroup/index.php?act=brandgroup&op=sign_message&' + Qs.stringify(data);
			}
		},
		methods: {
			refund(item) {
				// this.$http.post('/admin/afterSalesGroupBuy/index.php?act=signup&op=returnMoney', {
				// 	id: item.id
                // }).then(res => {
                // 	if (res.code == 1) {
                //         item.payStatus = 3;
                //     } else {
                // 		alert(res.msg);
                //     }
                // })
            },
           
            computedCheckStatus(code) {
                
				switch (code*1) {
					case 10:
						return '支付宝';
					case 6:
						return 'H5';
					case 2:
                        return '微信';
                    case 4:
						return '微信';
					case 8:
						return '小程序';
					case 1:
                        return 'APP';
                    case 9:
                        return 'APP';
                    case 11:
                        return 'APP';
                    case 12:
                        return 'APP';
                    case 999:
						return '其他';
				}
			},
			resetSearchData() {
				this.searchContent.groupName = '';
				this.searchContent.userName = '';
				this.searchContent.userPhone = '';
				this.searchContent.payStatus = '';
				this.searchContent.signUpChannel = '';
                this.searchContent.employeeName = '';
                this.searchContent.addTime = '';

			},
			search() {
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleSizeChange(pageSize) {
				this.searchContent.pageSize = pageSize;
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleCurrentChange(page) {
				this.searchContent.currentPage = page;
				this.getListData();
			},
			getListData() {
                const data = {};
                
				data.page = this.searchContent.currentPage;
				data.eachNum = this.searchContent.pageSize;
				data.bg_name = this.searchContent.groupName;
				data.sign_name = this.searchContent.userName;
				data.search_telephone = this.searchContent.userPhone;
				data.pay_status = this.searchContent.payStatus;
				data.bg_source = this.searchContent.signUpChannel;
                data.employee_name = this.searchContent.employeeName;
                if (this.searchContent.addTime) {
					const startAddMS = this.searchContent.addTime[0].getTime();
					const endAddMS = this.searchContent.addTime[1].getTime();
					if (startAddMS == endAddMS) {
						data.get_start_time = dateFormatter('YYYY-MM-DD ', startAddMS);
						data.get_end_time = dateFormatter('YYYY-MM-DD ', endAddMS + (24 * 60 * 60 - 1) * 1000);
                    } else {
						data.get_start_time = dateFormatter('YYYY-MM-DD ', this.searchContent.addTime[0]);
						data.get_end_time = dateFormatter('YYYY-MM-DD ', this.searchContent.addTime[1]);
                    }
				}
				this.$http.post('/admin/brandgroup/index.php?act=brandgroup&op=sign_message', data).then(res => {
					if (res.code == 1) {
						if (res.data && res.data.list.length) {
							this.signUpInfoList = res.data.list.map(function(item) {
								return {
									id: item.id,
									userName: item.username,
									userPhone: item.telephone,
									orderSerialNumber: item.pay_ordersn,
									groupName: item.brand_group_name,
									groupCategory: item.brand_name,
									signUpTime: item.addtime * 1000,
									channel: item.source,
									intentionMoney: item.pay_money,
									payStatus: item.pay_status
								}
							});
							this.total = parseInt(res.data.totalNum);
						} else {
							this.signUpInfoList = [];
							this.total = 0;
						}
					}
					else if (res.code == 2001) {
						this.signUpInfoList = [];
						this.total = 0;
					}
					else {
						alert(res.msg);
					}
				})
			}
		},
		mounted() {
			resize(this)
		},
		created() {
			if (this.$parent.tabLists[1] && this.$parent.tabLists[1].label == "审核" && this.$parent.tabLists[1].name == "group-detail") {
				this.$parent.tabLists.splice(1, 1);
			}
			this.getListData();
		},
		name: "sign-up-info"
	}
</script>

<style lang="scss" scoped>
    .sign-up-info {
        .search-content {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            &-input {
                width: 200px;
            }
            .time-range-wrapper {
                .time-range-label {
                    font-size: 14px;
                }
                display: flex;
                align-items: center;
                /deep/.el-range-separator {
                    box-sizing: content-box;
                }
            }
        }
        .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }
    .btn-bottom {
        background: #409EFF;
        color: #fff;
        border: 0;
        font-size: 14px;
        padding: 5px 8px;
        border-radius: 3px;
        display: inline-block;
    }
</style>